package com.goudan.practice.linkedlist;

/**
 * 链表反转 - 递归方式
 */
public class ReverseLinkedList {
    // 单向链表节点
    public static class Node {
        public int value;
        public Node next;

        public Node(int data) {
            value = data;
        }
    }

    public static void main(String[] args) {

    }

    /**
     * 递归反转方式
     */
    private Node reverseLinkedList(Node head) {
        if (head == null || head.next == null) {
            return head;
        }
        Node newHead = reverseLinkedList(head.next);
        head.next.next = head;
        head.next = null;
        return newHead;
    }

}
